package com.sfpay.coreplatform.account.service.inner.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.sfpay.coreplatform.account.common.AccountResponseCode;
import com.sfpay.coreplatform.account.common.enums.DrcrFlag;
import com.sfpay.coreplatform.account.common.enums.ExpenseFlag;
import com.sfpay.coreplatform.account.common.enums.TallySerialStatus;
import com.sfpay.coreplatform.account.persistence.dao.IAccountDao;
import com.sfpay.coreplatform.account.service.exception.AccountServiceException;
import com.sfpay.coreplatform.account.service.inner.IAccountPostingRuleService;
import com.sfpay.coreplatform.account.valueobject.dto.AccountPosting;
import com.sfpay.coreplatform.account.valueobject.dto.PaymentServiceGroup;
import com.sfpay.coreplatform.account.valueobject.dto.Transfer;
import com.sfpay.coreplatform.account.valueobject.tmo.AccountVO;
import com.sfpay.coreplatform.account.valueobject.tmo.TallySerial;
/**
 * 
 * 
 * 类说明：记账规则接口实现类
 *  
 * 
 * <p>
 * 详细描述：记账规则接口实现类
 *   
 * 
 * @author 308276 彭福明
 *   
 * CreateDate: 2012-2-14
 */
@Service
public class AccountPostingRuleServiceImpl implements IAccountPostingRuleService{

	private static Logger logger = LoggerFactory.getLogger(AccountPostingRuleServiceImpl.class);

	@Resource
	private IAccountDao accountDao;

	private static Map<String,PaymentServiceGroup> groupMap = new HashMap<String,PaymentServiceGroup>();

	static{
		//组装记账规则服务
		groupMap = buildPaymentServiceGroup();
	}

	/**
	 * 
	 *
	 * 方法说明：根据记账规则生成记账流水
	 *
	 * @param accountPosting 记账传入对象
	 * @return List<TallySerial> 记账流水
	 * @throws AccountServiceException 
	 */
	public List<TallySerial> generateTallySerials(Transfer accountPosting,Long prePayerBalanceAmount,Long prePayeeBalanceAmount,Long payerBalanceAmount,Long payeeBalanceAmount,boolean isPayerAsync,boolean isPayeeAsync) throws AccountServiceException{
		logger.info("AccountPostingRuleServiceImpl_generateTallySerials start");
		List<TallySerial> result = new ArrayList<TallySerial>();
		//组装借方记账流水
		TallySerial drTally = new TallySerial();
		drTally.setTallySource(accountPosting.getTallySource());
		drTally.setTallyType(accountPosting.getTallyType());
		drTally.setBusinessSN(accountPosting.getBusinessSN());
		drTally.setExpenseFlag(accountPosting.getExpenseFlag());
		drTally.setTransOrderNo(accountPosting.getTransOrderNo());
		drTally.setPaymentOrderNo(accountPosting.getPaymentOrderNo());
		drTally.setOrderNo(accountPosting.getOrderNo());
		drTally.setPaymentNo(accountPosting.getPaymentNo());
		//获取记账服务组
		PaymentServiceGroup group = (PaymentServiceGroup)groupMap.get(accountPosting.getOrderNo()+"_"+accountPosting.getPaymentNo()+"_"+accountPosting.getExpenseFlag());
		if(group == null){
			logger.error("acct_posting_servicegroup_notexist:OrderNo["+accountPosting.getOrderNo()+"],PaymentNo["+accountPosting.getPaymentNo()+"]"+ "ExpenseFlag[" + accountPosting.getExpenseFlag() + "]");
			throw new AccountServiceException(AccountResponseCode.ACCT_POSTING_SERVICEGROUP_NOTEXIST,"acct_posting_servicegroup_notexist:OrderNo["+accountPosting.getOrderNo()+"],PaymentNo["+accountPosting.getPaymentNo()+"]"+ "ExpenseFlag[" + accountPosting.getExpenseFlag() + "]");
		}
		drTally.setServiceGroupNo(group.getPaymentServiceGroupCode());
		drTally.setServiceNo(group.getPaymentServiceCode());
		drTally.setDrcrFlag(DrcrFlag.DR);
		//根据账户编号查询科目编号
		Long drSubjectNo = querySubjectNoByAcctNo(accountPosting.getPayerAccount());
		drTally.setSubjectNo(drSubjectNo);
		drTally.setDrcrAmount(accountPosting.getAmount());
		drTally.setAccountNo(accountPosting.getPayerAccount());
		drTally.setPreAccountAmount(prePayerBalanceAmount);
		drTally.setAccountAmount(payerBalanceAmount);
		if(isPayerAsync == true){
			drTally.setStatus(TallySerialStatus.INIT);
		}else{
			drTally.setStatus(TallySerialStatus.SUCCESS);
		}
		drTally.setOperatorId(accountPosting.getOperatorId());
		result.add(drTally);

		//组装贷方记账流水
		TallySerial crTally = new TallySerial();
		crTally.setTallySource(accountPosting.getTallySource());
		crTally.setTallyType(accountPosting.getTallyType());
		crTally.setBusinessSN(accountPosting.getBusinessSN());
		crTally.setExpenseFlag(accountPosting.getExpenseFlag());
		crTally.setTransOrderNo(accountPosting.getTransOrderNo());
		crTally.setPaymentOrderNo(accountPosting.getPaymentOrderNo());
		crTally.setOrderNo(accountPosting.getOrderNo());
		crTally.setPaymentNo(accountPosting.getPaymentNo());
		crTally.setServiceGroupNo(group.getPaymentServiceGroupCode());
		crTally.setServiceNo(group.getPaymentServiceCode());
		crTally.setDrcrFlag(DrcrFlag.CR);
		//根据账户编号查询科目编号
		Long crSubjectNo = querySubjectNoByAcctNo(accountPosting.getPayeeAccount());
		crTally.setSubjectNo(crSubjectNo);
		crTally.setDrcrAmount(accountPosting.getAmount());
		crTally.setAccountNo(accountPosting.getPayeeAccount());
		crTally.setPreAccountAmount(prePayeeBalanceAmount);
		crTally.setAccountAmount(payeeBalanceAmount);
		if(isPayeeAsync == true){
			crTally.setStatus(TallySerialStatus.INIT);
		}else{
			crTally.setStatus(TallySerialStatus.SUCCESS);
		}
		crTally.setOperatorId(accountPosting.getOperatorId());
		result.add(crTally);
		logger.info("AccountPostingRuleServiceImpl_generateTallySerials end");
		return result;
	}

	/**
	 * 
	 *
	 * 方法说明：组装记账服务组
	 *
	 * @return
	 */
	private static Map<String,PaymentServiceGroup> buildPaymentServiceGroup(){
		Map<String,PaymentServiceGroup> groupMap = new HashMap<String,PaymentServiceGroup>();
		//提现退款
		PaymentServiceGroup group910_101_P = new PaymentServiceGroup();
		group910_101_P.setPaymentServiceGroupCode("201");
		group910_101_P.setPaymentServiceCode("301");
		groupMap.put("910_101_"+ExpenseFlag.PAYMENT, group910_101_P);
		PaymentServiceGroup group910_101_E = new PaymentServiceGroup();
		group910_101_E.setPaymentServiceGroupCode("201");
		group910_101_E.setPaymentServiceCode("302");
		groupMap.put("910_101_"+ExpenseFlag.EXPENSE, group910_101_E);

		PaymentServiceGroup group910_102_P = new PaymentServiceGroup();
		group910_102_P.setPaymentServiceGroupCode("202");
		group910_102_P.setPaymentServiceCode("303");
		groupMap.put("910_102_"+ExpenseFlag.PAYMENT, group910_102_P);
		PaymentServiceGroup group910_102_E = new PaymentServiceGroup();
		group910_102_E.setPaymentServiceGroupCode("202");
		group910_102_E.setPaymentServiceCode("304");
		groupMap.put("910_102_"+ExpenseFlag.EXPENSE, group910_102_E);

		PaymentServiceGroup group910_103_P = new PaymentServiceGroup();
		group910_103_P.setPaymentServiceGroupCode("203");
		group910_103_P.setPaymentServiceCode("305");
		groupMap.put("910_103_"+ExpenseFlag.PAYMENT, group910_103_P);
		PaymentServiceGroup group910_103_E = new PaymentServiceGroup();
		group910_103_E.setPaymentServiceGroupCode("203");
		group910_103_E.setPaymentServiceCode("306");
		groupMap.put("910_103_"+ExpenseFlag.EXPENSE, group910_103_E);

		//提现退款
		PaymentServiceGroup group915_104_P = new PaymentServiceGroup();
		group915_104_P.setPaymentServiceGroupCode("204");
		group915_104_P.setPaymentServiceCode("307");
		groupMap.put("915_104_"+ExpenseFlag.PAYMENT, group915_104_P);

		PaymentServiceGroup group915_105_P = new PaymentServiceGroup();
		group915_105_P.setPaymentServiceGroupCode("205");
		group915_105_P.setPaymentServiceCode("308");
		groupMap.put("915_105_"+ExpenseFlag.PAYMENT, group915_105_P);
		PaymentServiceGroup group915_105_E = new PaymentServiceGroup();
		group915_105_E.setPaymentServiceGroupCode("205");
		group915_105_E.setPaymentServiceCode("309");
		groupMap.put("915_105_"+ExpenseFlag.EXPENSE, group915_105_E);

		//付款到银行
		PaymentServiceGroup group920_106_P = new PaymentServiceGroup();
		group920_106_P.setPaymentServiceGroupCode("206");
		group920_106_P.setPaymentServiceCode("310");
		groupMap.put("920_106_"+ExpenseFlag.PAYMENT, group920_106_P);
		PaymentServiceGroup group920_106_E = new PaymentServiceGroup();
		group920_106_E.setPaymentServiceGroupCode("206");
		group920_106_E.setPaymentServiceCode("311");
		groupMap.put("920_106_"+ExpenseFlag.EXPENSE, group920_106_E);

		PaymentServiceGroup group920_107_P = new PaymentServiceGroup();
		group920_107_P.setPaymentServiceGroupCode("207");
		group920_107_P.setPaymentServiceCode("312");
		groupMap.put("920_107_"+ExpenseFlag.PAYMENT, group920_107_P);
		PaymentServiceGroup group920_107_E = new PaymentServiceGroup();
		group920_107_E.setPaymentServiceGroupCode("207");
		group920_107_E.setPaymentServiceCode("313");
		groupMap.put("920_107_"+ExpenseFlag.EXPENSE, group920_107_E);

		PaymentServiceGroup group920_108_P = new PaymentServiceGroup();
		group920_108_P.setPaymentServiceGroupCode("208");
		group920_108_P.setPaymentServiceCode("314");
		groupMap.put("920_108_"+ExpenseFlag.PAYMENT, group920_108_P);
		PaymentServiceGroup group920_108_E = new PaymentServiceGroup();
		group920_108_E.setPaymentServiceGroupCode("208");
		group920_108_E.setPaymentServiceCode("315");
		groupMap.put("920_108_"+ExpenseFlag.EXPENSE, group920_108_E);

		//付款到银行退款
		PaymentServiceGroup group925_109_P = new PaymentServiceGroup();
		group925_109_P.setPaymentServiceGroupCode("209");
		group925_109_P.setPaymentServiceCode("316");
		groupMap.put("925_109_"+ExpenseFlag.PAYMENT, group925_109_P);

		PaymentServiceGroup group925_110_P = new PaymentServiceGroup();
		group925_110_P.setPaymentServiceGroupCode("210");
		group925_110_P.setPaymentServiceCode("317");
		groupMap.put("925_110_"+ExpenseFlag.PAYMENT, group925_110_P);
		PaymentServiceGroup group925_110_E = new PaymentServiceGroup();
		group925_110_E.setPaymentServiceGroupCode("210");
		group925_110_E.setPaymentServiceCode("318");
		groupMap.put("925_110_"+ExpenseFlag.EXPENSE, group925_110_E);

		PaymentServiceGroup group925_111_P = new PaymentServiceGroup();
		group925_111_P.setPaymentServiceGroupCode("211");
		group925_111_P.setPaymentServiceCode("319");
		groupMap.put("925_110_"+ExpenseFlag.PAYMENT, group925_111_P);
		PaymentServiceGroup group925_111_E = new PaymentServiceGroup();
		group925_111_E.setPaymentServiceGroupCode("211");
		group925_111_E.setPaymentServiceCode("320");
		groupMap.put("925_111_"+ExpenseFlag.EXPENSE, group925_111_E);

		//充值
		PaymentServiceGroup group930_112_P = new PaymentServiceGroup();
		group930_112_P.setPaymentServiceGroupCode("212");
		group930_112_P.setPaymentServiceCode("321");
		groupMap.put("930_112_"+ExpenseFlag.PAYMENT, group930_112_P);
		PaymentServiceGroup group930_112_E = new PaymentServiceGroup();
		group930_112_E.setPaymentServiceGroupCode("212");
		group930_112_E.setPaymentServiceCode("322");
		groupMap.put("930_112_"+ExpenseFlag.EXPENSE, group930_112_E);

		PaymentServiceGroup group930_113_P = new PaymentServiceGroup();
		group930_113_P.setPaymentServiceGroupCode("213");
		group930_113_P.setPaymentServiceCode("323");
		groupMap.put("930_113_"+ExpenseFlag.PAYMENT, group930_113_P);
		PaymentServiceGroup group930_113_E = new PaymentServiceGroup();
		group930_113_E.setPaymentServiceGroupCode("213");
		group930_113_E.setPaymentServiceCode("324");
		groupMap.put("930_113_"+ExpenseFlag.EXPENSE, group930_113_E);

		//支付网关
		PaymentServiceGroup group940_115_P = new PaymentServiceGroup();
		group940_115_P.setPaymentServiceGroupCode("215");
		group940_115_P.setPaymentServiceCode("327");
		groupMap.put("940_115_"+ExpenseFlag.PAYMENT, group940_115_P);
		PaymentServiceGroup group940_115_E = new PaymentServiceGroup();
		group940_115_E.setPaymentServiceGroupCode("215");
		group940_115_E.setPaymentServiceCode("328");
		groupMap.put("940_115_"+ExpenseFlag.EXPENSE, group940_115_E);

		PaymentServiceGroup group940_116_P = new PaymentServiceGroup();
		group940_116_P.setPaymentServiceGroupCode("216");
		group940_116_P.setPaymentServiceCode("329");
		groupMap.put("940_116_"+ExpenseFlag.PAYMENT, group940_116_P);
		PaymentServiceGroup group940_116_E = new PaymentServiceGroup();
		group940_116_E.setPaymentServiceGroupCode("216");
		group940_116_E.setPaymentServiceCode("330");
		groupMap.put("940_116_"+ExpenseFlag.EXPENSE, group940_116_E);

		//网关退款
		PaymentServiceGroup group945_117_P = new PaymentServiceGroup();
		group945_117_P.setPaymentServiceGroupCode("217");
		group945_117_P.setPaymentServiceCode("331");
		groupMap.put("945_117_"+ExpenseFlag.PAYMENT, group945_117_P);

		PaymentServiceGroup group945_118_P = new PaymentServiceGroup();
		group945_118_P.setPaymentServiceGroupCode("218");
		group945_118_P.setPaymentServiceCode("332");
		groupMap.put("945_118_"+ExpenseFlag.PAYMENT, group945_118_P);
		PaymentServiceGroup group945_118_E = new PaymentServiceGroup();
		group945_118_E.setPaymentServiceGroupCode("218");
		group945_118_E.setPaymentServiceCode("333");
		groupMap.put("945_118_"+ExpenseFlag.EXPENSE, group945_118_E);

		PaymentServiceGroup group945_119_P = new PaymentServiceGroup();
		group945_119_P.setPaymentServiceGroupCode("219");
		group945_119_P.setPaymentServiceCode("331");
		groupMap.put("945_119_"+ExpenseFlag.PAYMENT, group945_119_P);

		PaymentServiceGroup group945_120_P = new PaymentServiceGroup();
		group945_120_P.setPaymentServiceGroupCode("220");
		group945_120_P.setPaymentServiceCode("334");
		groupMap.put("945_120_"+ExpenseFlag.PAYMENT, group945_120_P);
		PaymentServiceGroup group945_120_E = new PaymentServiceGroup();
		group945_120_E.setPaymentServiceGroupCode("220");
		group945_120_E.setPaymentServiceCode("335");
		groupMap.put("945_120_"+ExpenseFlag.EXPENSE, group945_120_E);

		//虚拟账户到虚拟账户
		PaymentServiceGroup group950_121_P = new PaymentServiceGroup();
		group950_121_P.setPaymentServiceGroupCode("221");
		group950_121_P.setPaymentServiceCode("336");
		groupMap.put("950_121_"+ExpenseFlag.PAYMENT, group950_121_P);
		PaymentServiceGroup group950_121_E = new PaymentServiceGroup();
		group950_121_E.setPaymentServiceGroupCode("221");
		group950_121_E.setPaymentServiceCode("337");
		groupMap.put("950_121_"+ExpenseFlag.EXPENSE, group950_121_E);

		PaymentServiceGroup group950_122_P = new PaymentServiceGroup();
		group950_122_P.setPaymentServiceGroupCode("222");
		group950_122_P.setPaymentServiceCode("338");
		groupMap.put("950_122_"+ExpenseFlag.PAYMENT, group950_122_P);
		PaymentServiceGroup group950_122_E = new PaymentServiceGroup();
		group950_122_E.setPaymentServiceGroupCode("222");
		group950_122_E.setPaymentServiceCode("339");
		groupMap.put("950_122_"+ExpenseFlag.EXPENSE, group950_122_E);

		//速运POS刷卡交易
		PaymentServiceGroup group960_123_P = new PaymentServiceGroup();
		group960_123_P.setPaymentServiceGroupCode("223");
		group960_123_P.setPaymentServiceCode("340");
		groupMap.put("960_123_"+ExpenseFlag.PAYMENT, group960_123_P);
		PaymentServiceGroup group960_123_E = new PaymentServiceGroup();
		group960_123_E.setPaymentServiceGroupCode("223");
		group960_123_E.setPaymentServiceCode("341");
		groupMap.put("960_123_"+ExpenseFlag.EXPENSE, group960_123_E);

		PaymentServiceGroup group960_124_P = new PaymentServiceGroup();
		group960_124_P.setPaymentServiceGroupCode("224");
		group960_124_P.setPaymentServiceCode("342");
		groupMap.put("960_124_"+ExpenseFlag.PAYMENT, group960_124_P);

		PaymentServiceGroup group960_125_P = new PaymentServiceGroup();
		group960_125_P.setPaymentServiceGroupCode("225");
		group960_125_P.setPaymentServiceCode("343");
		groupMap.put("960_125_"+ExpenseFlag.PAYMENT, group960_125_P);

		PaymentServiceGroup group960_126_P = new PaymentServiceGroup();
		group960_126_P.setPaymentServiceGroupCode("226");
		group960_126_P.setPaymentServiceCode("344");
		groupMap.put("960_126_"+ExpenseFlag.PAYMENT, group960_126_P);

		//普通担保POS刷卡交易
		PaymentServiceGroup group961_127_P = new PaymentServiceGroup();
		group961_127_P.setPaymentServiceGroupCode("227");
		group961_127_P.setPaymentServiceCode("345");
		groupMap.put("961_127_"+ExpenseFlag.PAYMENT, group961_127_P);
		PaymentServiceGroup group961_127_E = new PaymentServiceGroup();
		group961_127_E.setPaymentServiceGroupCode("227");
		group961_127_E.setPaymentServiceCode("346");
		groupMap.put("961_127_"+ExpenseFlag.EXPENSE, group961_127_E);

		PaymentServiceGroup group961_128_P = new PaymentServiceGroup();
		group961_128_P.setPaymentServiceGroupCode("228");
		group961_128_P.setPaymentServiceCode("347");
		groupMap.put("961_128_"+ExpenseFlag.PAYMENT, group961_128_P);

		//普通POS刷卡交易
		PaymentServiceGroup group962_129_P = new PaymentServiceGroup();
		group962_129_P.setPaymentServiceGroupCode("229");
		group962_129_P.setPaymentServiceCode("348");
		groupMap.put("962_129_"+ExpenseFlag.PAYMENT, group962_129_P);
		PaymentServiceGroup group962_129_E = new PaymentServiceGroup();
		group962_129_E.setPaymentServiceGroupCode("229");
		group962_129_E.setPaymentServiceCode("349");
		groupMap.put("962_129_"+ExpenseFlag.EXPENSE, group962_129_E);

		//冻结/解冻
		PaymentServiceGroup group970_130_P = new PaymentServiceGroup();
		group970_130_P.setPaymentServiceGroupCode("230");
		group970_130_P.setPaymentServiceCode("350");
		groupMap.put("970_130_"+ExpenseFlag.PAYMENT, group970_130_P);

		PaymentServiceGroup group970_131_P = new PaymentServiceGroup();
		group970_131_P.setPaymentServiceGroupCode("231");
		group970_131_P.setPaymentServiceCode("351");
		groupMap.put("970_131_"+ExpenseFlag.PAYMENT, group970_131_P);

		//特殊转账
		PaymentServiceGroup group500_134_P = new PaymentServiceGroup();
		group500_134_P.setPaymentServiceGroupCode("234");
		group500_134_P.setPaymentServiceCode("354");
		groupMap.put("500_134_"+ExpenseFlag.PAYMENT, group500_134_P);

		//销卡 SF储值卡销卡转账
		PaymentServiceGroup group981_133_P = new PaymentServiceGroup();
		group981_133_P.setPaymentServiceGroupCode("233");
		group981_133_P.setPaymentServiceCode("355");
		groupMap.put("981_133_"+ExpenseFlag.PAYMENT, group981_133_P);


		//充值
		PaymentServiceGroup group982_136_P = new PaymentServiceGroup();
		group982_136_P.setPaymentServiceGroupCode("236");
		group982_136_P.setPaymentServiceCode("357");
		groupMap.put("982_136_"+ExpenseFlag.PAYMENT, group982_136_P);

		//储值卡大额充值
		PaymentServiceGroup group990_164_P = new PaymentServiceGroup();
		group990_164_P.setPaymentServiceGroupCode("264");
		group990_164_P.setPaymentServiceCode("385");
		groupMap.put("990_164_"+ExpenseFlag.PAYMENT, group990_164_P);

		//充值短款处理
		PaymentServiceGroup group983_137_P = new PaymentServiceGroup();
		group983_137_P.setPaymentServiceGroupCode("237");
		group983_137_P.setPaymentServiceCode("358");
		groupMap.put("983_137_"+ExpenseFlag.PAYMENT, group983_137_P);

		//工本费
		PaymentServiceGroup group984_138_P = new PaymentServiceGroup();
		group984_138_P.setPaymentServiceGroupCode("238");
		group984_138_P.setPaymentServiceCode("359");
		groupMap.put("984_138_"+ExpenseFlag.PAYMENT, group984_138_P);

		//积分赠送
		PaymentServiceGroup group985_139_P = new PaymentServiceGroup();
		group985_139_P.setPaymentServiceGroupCode("239");
		group985_139_P.setPaymentServiceCode("360");
		groupMap.put("985_139_"+ExpenseFlag.PAYMENT, group985_139_P);

		//消费
		PaymentServiceGroup group986_140_P = new PaymentServiceGroup();
		group986_140_P.setPaymentServiceGroupCode("240");
		group986_140_P.setPaymentServiceCode("361");
		groupMap.put("986_140_"+ExpenseFlag.PAYMENT, group986_140_P);

		//消费撤销、退款
		PaymentServiceGroup group987_141_P = new PaymentServiceGroup();
		group987_141_P.setPaymentServiceGroupCode("241");
		group987_141_P.setPaymentServiceCode("362");
		groupMap.put("987_141_"+ExpenseFlag.PAYMENT, group987_141_P);

		//充值撤销
		PaymentServiceGroup group988_142_P = new PaymentServiceGroup();
		group988_142_P.setPaymentServiceGroupCode("242");
		group988_142_P.setPaymentServiceCode("363");
		groupMap.put("988_142_"+ExpenseFlag.PAYMENT, group988_142_P);

		//积分赠送退款
		PaymentServiceGroup group989_143_P = new PaymentServiceGroup();
		group989_143_P.setPaymentServiceGroupCode("243");
		group989_143_P.setPaymentServiceCode("364");
		groupMap.put("989_143_"+ExpenseFlag.PAYMENT, group989_143_P);


		/**
		 * 商务卡
		 */
		//消费
		PaymentServiceGroup group700_144_P = new PaymentServiceGroup();
		group700_144_P.setPaymentServiceGroupCode("244");
		group700_144_P.setPaymentServiceCode("365");
		groupMap.put("700_144_"+ExpenseFlag.PAYMENT, group700_144_P);

		//现金还款
		PaymentServiceGroup group701_145_P = new PaymentServiceGroup();
		group701_145_P.setPaymentServiceGroupCode("245");
		group701_145_P.setPaymentServiceCode("366");
		groupMap.put("701_145_"+ExpenseFlag.PAYMENT, group701_145_P);

		//网银还款
		PaymentServiceGroup group702_146_P = new PaymentServiceGroup();
		group702_146_P.setPaymentServiceGroupCode("246");
		group702_146_P.setPaymentServiceCode("367");
		groupMap.put("702_146_"+ExpenseFlag.PAYMENT, group702_146_P);

		//POS还款
		PaymentServiceGroup group703_147_P = new PaymentServiceGroup();
		group703_147_P.setPaymentServiceGroupCode("247");
		group703_147_P.setPaymentServiceCode("368");
		groupMap.put("703_147_"+ExpenseFlag.PAYMENT, group703_147_P);

		//运费打折
		PaymentServiceGroup group704_148_P = new PaymentServiceGroup();
		group704_148_P.setPaymentServiceGroupCode("248");
		group704_148_P.setPaymentServiceCode("369");
		groupMap.put("704_148_"+ExpenseFlag.PAYMENT, group704_148_P);

		//消费退款
		PaymentServiceGroup group713_159_P = new PaymentServiceGroup();
		group713_159_P.setPaymentServiceGroupCode("259");
		group713_159_P.setPaymentServiceCode("380");
		groupMap.put("713_159_"+ExpenseFlag.PAYMENT, group713_159_P);

		//商务卡账单转账
		PaymentServiceGroup group714_160_P = new PaymentServiceGroup();
		group714_160_P.setPaymentServiceGroupCode("260");
		group714_160_P.setPaymentServiceCode("381");
		groupMap.put("714_160_"+ExpenseFlag.PAYMENT, group714_160_P);

		//商务卡工本费
		PaymentServiceGroup group717_163_P = new PaymentServiceGroup();
		group717_163_P.setPaymentServiceGroupCode("263");
		group717_163_P.setPaymentServiceCode("384");
		groupMap.put("717_163_"+ExpenseFlag.PAYMENT, group717_163_P);


		/**
		 * 网银/银企直联结算（通过第三方结算，然后在运营后台录入结算金额）
		 */
		//消费
		PaymentServiceGroup group705_149_P = new PaymentServiceGroup();
		group705_149_P.setPaymentServiceGroupCode("249");
		group705_149_P.setPaymentServiceCode("370");
		groupMap.put("705_149_"+ExpenseFlag.PAYMENT, group705_149_P);

		/**
		 * 银企直联
		 */

		//银企直联出款 出款步骤一
		PaymentServiceGroup group706_150_P = new PaymentServiceGroup();
		group706_150_P.setPaymentServiceGroupCode("250");
		group706_150_P.setPaymentServiceCode("371");
		groupMap.put("706_150_"+ExpenseFlag.PAYMENT, group706_150_P);

		//银企直联出款 出款步骤二
		PaymentServiceGroup group706_151_P = new PaymentServiceGroup();
		group706_151_P.setPaymentServiceGroupCode("251");
		group706_151_P.setPaymentServiceCode("372");
		groupMap.put("706_151_"+ExpenseFlag.PAYMENT, group706_151_P);

		//银企直联出款失败退款(付款给顺丰)
		PaymentServiceGroup group715_161_P = new PaymentServiceGroup();
		group715_161_P.setPaymentServiceGroupCode("261");
		group715_161_P.setPaymentServiceCode("382");
		groupMap.put("715_161_"+ExpenseFlag.PAYMENT, group715_161_P);

		/**
		 * POS、代收保费
		 */
		//POS刷卡交易（除代收保费）
		PaymentServiceGroup group707_152_P = new PaymentServiceGroup();
		group707_152_P.setPaymentServiceGroupCode("252");
		group707_152_P.setPaymentServiceCode("373");
		groupMap.put("707_152_"+ExpenseFlag.PAYMENT, group707_152_P);

		//POS刷卡交易撤销（除代收保费）
		PaymentServiceGroup group716_162_P = new PaymentServiceGroup();
		group716_162_P.setPaymentServiceGroupCode("262");
		group716_162_P.setPaymentServiceCode("383");
		groupMap.put("716_162_"+ExpenseFlag.PAYMENT, group716_162_P);

		//收保费
		PaymentServiceGroup group708_153_P = new PaymentServiceGroup();
		group708_153_P.setPaymentServiceGroupCode("253");
		group708_153_P.setPaymentServiceCode("374");
		groupMap.put("708_153_"+ExpenseFlag.PAYMENT, group708_153_P);

		//月结运费POS刷卡
		PaymentServiceGroup group711_156_P = new PaymentServiceGroup();
		group711_156_P.setPaymentServiceGroupCode("256");
		group711_156_P.setPaymentServiceCode("377");
		groupMap.put("711_156_"+ExpenseFlag.PAYMENT, group711_156_P);
		
		//一巴一输长款记账-长款记账
		PaymentServiceGroup group730_172_P = new PaymentServiceGroup();
		group730_172_P.setPaymentServiceGroupCode("272");
		group730_172_P.setPaymentServiceCode("410");
		groupMap.put("730_172_"+ExpenseFlag.PAYMENT, group730_172_P);
				
		//一巴一输长款记账-长款退款
		PaymentServiceGroup group731_173_P = new PaymentServiceGroup();
		group731_173_P.setPaymentServiceGroupCode("273");
		group731_173_P.setPaymentServiceCode("411");
		groupMap.put("731_173_"+ExpenseFlag.PAYMENT, group731_173_P);
				
		//一巴一输长款记账-长款清理
		PaymentServiceGroup group733_175_P = new PaymentServiceGroup();
		group733_175_P.setPaymentServiceGroupCode("275");
		group733_175_P.setPaymentServiceCode("413");
		groupMap.put("733_175_"+ExpenseFlag.PAYMENT, group733_175_P);
		
		//预付货款记账-集团收入户转款至预付货款专户
		PaymentServiceGroup group744_187_P = new PaymentServiceGroup();
		group744_187_P.setPaymentServiceGroupCode("287");
		group744_187_P.setPaymentServiceCode("425");
		groupMap.put("744_187_"+ExpenseFlag.PAYMENT, group744_187_P);
		
		//预付货款记账-预付货款
		PaymentServiceGroup group745_188_P = new PaymentServiceGroup();
		group745_188_P.setPaymentServiceGroupCode("288");
		group745_188_P.setPaymentServiceCode("426");
		groupMap.put("745_188_"+ExpenseFlag.PAYMENT, group745_188_P);
		
		//预付货款记账-提现驳回后，风控最终确认该客户终止交易，订单取消时
		PaymentServiceGroup group746_189_P = new PaymentServiceGroup();
		group746_189_P.setPaymentServiceGroupCode("289");
		group746_189_P.setPaymentServiceCode("427");
		groupMap.put("746_189_"+ExpenseFlag.PAYMENT, group746_189_P);
		
		//预付货款记账-预付货款客户提现
		PaymentServiceGroup group747_190_P = new PaymentServiceGroup();
		group747_190_P.setPaymentServiceGroupCode("290");
		group747_190_P.setPaymentServiceCode("428");
		groupMap.put("747_190_"+ExpenseFlag.PAYMENT, group747_190_P);
		
		PaymentServiceGroup group747_191_P = new PaymentServiceGroup();
		group747_191_P.setPaymentServiceGroupCode("291");
		group747_191_P.setPaymentServiceCode("429");
		groupMap.put("747_191_"+ExpenseFlag.PAYMENT, group747_191_P);
		
		PaymentServiceGroup group747_192_P = new PaymentServiceGroup();
		group747_192_P.setPaymentServiceGroupCode("292");
		group747_192_P.setPaymentServiceCode("430");
		groupMap.put("747_192_"+ExpenseFlag.PAYMENT, group747_192_P);
		
		//预付货款记账-预付货款计费
		PaymentServiceGroup group748_193_P = new PaymentServiceGroup();
		group748_193_P.setPaymentServiceGroupCode("293");
		group748_193_P.setPaymentServiceCode("431");
		groupMap.put("748_193_"+ExpenseFlag.PAYMENT, group748_193_P);
		
		//预付货款记账-COD结算还款-本金
		PaymentServiceGroup group749_194_P = new PaymentServiceGroup();
		group749_194_P.setPaymentServiceGroupCode("294");
		group749_194_P.setPaymentServiceCode("432");
		groupMap.put("749_194_"+ExpenseFlag.PAYMENT, group749_194_P);
		
		//预付货款记账-COD结算还款-服务费
		PaymentServiceGroup group750_195_P = new PaymentServiceGroup();
		group750_195_P.setPaymentServiceGroupCode("295");
		group750_195_P.setPaymentServiceCode("433");
		groupMap.put("750_195_"+ExpenseFlag.PAYMENT, group750_195_P);
		
		//预付货款记账-线下还款-本金
		PaymentServiceGroup group751_196_P = new PaymentServiceGroup();
		group751_196_P.setPaymentServiceGroupCode("296");
		group751_196_P.setPaymentServiceCode("434");
		groupMap.put("751_196_"+ExpenseFlag.PAYMENT, group751_196_P);
		
		//预付货款记账-线下还款-服务费
		PaymentServiceGroup group752_197_P = new PaymentServiceGroup();
		group752_197_P.setPaymentServiceGroupCode("297");
		group752_197_P.setPaymentServiceCode("435");
		groupMap.put("752_197_"+ExpenseFlag.PAYMENT, group752_197_P);



		return groupMap;
	}

	/**
	 * 
	 *
	 * 方法说明：根据账户编号查询科目编号
	 *
	 * @param acctNo 账户编号
	 * @return 科目编号
	 */
	private Long querySubjectNoByAcctNo(Long acctNo){
		AccountVO accountVO = accountDao.selectByAccountNo(acctNo);
		if(accountVO == null){
			return null;
		}
		return Long.valueOf(accountVO.getSubjectNo());
	}

}
